package com.xiaoshuidi.cloud.module.finance.service.finance.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xiaoshuidi.cloud.framework.common.pojo.PageParam;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.finance.dal.dataobject.finance.FinanceBankAreaDO;
import com.xiaoshuidi.cloud.module.finance.dal.dataobject.finance.FinanceBankDO;
import com.xiaoshuidi.cloud.module.finance.dal.mysql.finance.FinanceBankAreaMapper;
import com.xiaoshuidi.cloud.module.finance.dal.mysql.finance.FinanceBankMapper;
import com.xiaoshuidi.cloud.module.finance.service.finance.FinanceBankService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FinanceBankServiceImpl implements FinanceBankService {
    @Resource
    private FinanceBankMapper financeBankMapper;
    @Resource
    private FinanceBankAreaMapper financeBankAreaMapper;

    @Override
    public List<FinanceBankAreaDO> getBankAreaList(Integer type, Integer parentId) {
        return financeBankAreaMapper.selectList(Wrappers.<FinanceBankAreaDO>query()
                .eq(true, "type", type)
                .eq(true, "parent_id", parentId)
                .orderByDesc("sort"));
    }

    @Override
    public List<FinanceBankDO> getBankList(String province, String city) {
        return financeBankMapper.selectList(Wrappers.<FinanceBankDO>query()
                .eq(true, "bank_province", province)
                .eq(true, "bank_city", city));
    }

    @Override
    public List<FinanceBankDO> getBankPage(String province, String city, String name) {
        PageResult<FinanceBankDO> pageResult =  financeBankMapper.selectPage(new PageParam(), new QueryWrapper<FinanceBankDO>()
                .eq(StringUtils.hasText(province), "bank_province", province)
                .eq(StringUtils.hasText(city), "bank_city", city)
                .like(StringUtils.hasText(name), "bank_name", name)
        );
        return pageResult.getList();
    }

    @Override
    public FinanceBankDO getBankByCode(String bankCode) {
        return financeBankMapper.selectByBankCode(bankCode);
    }
}
